package com.windy.myvideo;

import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.windy.myvideo.player.WindyPlayer;


/**
 * Created by dingfeng on 2016/9/12.
 */
public class MyPlayerActivity extends AppCompatActivity {

    private Uri mUri;

    String url = "/sdcard/shark.mp4";
//    String url = "/sdcard/ming.rmvb";

    private WindyPlayer mWindyPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_player);

        mWindyPlayer = new WindyPlayer(MyPlayerActivity.this);
//        mWindyPlayer.play(url);
//        mWindyPlayer.setTitle(url);

        handleIntent(getIntent());
    }

    private void handleIntent(Intent intent) {
        if (intent != null) {
            mUri = intent.getData();
            if (mUri != null) {
                mWindyPlayer.play(mUri.toString());
                mWindyPlayer.setTitle(mUri.toString());
            } else {
                mWindyPlayer.play(url);
                mWindyPlayer.setTitle(url);
            }
        } else {
            mWindyPlayer.play(url);
            mWindyPlayer.setTitle(url);
        }
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        mWindyPlayer.onConfigurationChanged(newConfig);
    }

    @Override
    public void onBackPressed() {
        if (mWindyPlayer == null || !mWindyPlayer.onBackPressed()) {
            super.onBackPressed();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        mWindyPlayer.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
        mWindyPlayer.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mWindyPlayer.onDestroy();
    }
}

